/*
 * AlertaViewImp.java
 *
 */
package vista.Alerta;

import Utilidades.Errores;
import vista.*;
import java.sql.SQLException;
import controlador.AlertaControlador;
import java.util.ArrayList;
import java.util.List;
import modelo.entidades.Alerta;
import modelo.AlertaModelo;

public class AlertaVistaImp extends AbstractVistaImp<AlertaControlador, AlertaModelo> implements AlertaVista {

    private AlertaTableModel tableModel;
    private AlertaVistaInterior panelAlerta;

    public AlertaVistaImp() {
        tableModel = AlertaTableModel.create();
        initComponents();

        this.panelAlerta = new AlertaVistaInterior(this);
        this.jPanelAlerta.add(this.panelAlerta);
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        jTableAlerta = new javax.swing.JTable();
        jPanelAlerta = new javax.swing.JPanel();

        jTableAlerta.setModel(tableModel);
        jTableAlerta.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jTableAlertaMouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(jTableAlerta);

        jPanelAlerta.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));
        jPanelAlerta.setLayout(new javax.swing.BoxLayout(jPanelAlerta, javax.swing.BoxLayout.LINE_AXIS));

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanelAlerta, javax.swing.GroupLayout.DEFAULT_SIZE, 565, Short.MAX_VALUE)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 565, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 140, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jPanelAlerta, javax.swing.GroupLayout.DEFAULT_SIZE, 328, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void jTableAlertaMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTableAlertaMouseClicked
        AlertaTableModel alertaTableModel = (AlertaTableModel) this.jTableAlerta.getModel();
        Alerta alerta = alertaTableModel.getRow(this.jTableAlerta.getSelectedRow());
        panelAlerta.setAlerta(alerta);
    }//GEN-LAST:event_jTableAlertaMouseClicked
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JPanel jPanelAlerta;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable jTableAlerta;
    // End of variables declaration//GEN-END:variables

    @Override
    public void refresh() {
        try {
            tableModel.setAlertas(getModel().listar()); 
        } catch (SQLException ex) {
            Errores.mostrarError(ex);
        } catch (Exception ex) {
            Errores.mostrarError(ex);
        }
    }

    protected void fireActualizaAlertaGesture(String matricula, String fecha, String tipo, String atendida, String Observa) {
        List<String> datos = new ArrayList<String>();
        datos.add(matricula);
        datos.add(fecha);
        datos.add(tipo);
        datos.add(atendida);
        datos.add(Observa);

        getController().actualizaEntidadGesture(datos);
    }
}
